package com.netcracker.studportal.server.junit_test;

import junit.framework.TestCase;

import com.netcracker.studportal.server.model.Student;
import com.netcracker.studportal.server.model.User;
import com.netcracker.studportal.server.util.FactoryDAO;

public class TestUserDAOImpl extends TestCase {
    FactoryDAO f=new FactoryDAO();
	
	public TestUserDAOImpl(String testName)  {
        super(testName);
    }
	
	public void testgetById() {
		User u = null;
		try {
			u = f.getUsersDAO().getById(new Long(1));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		assertTrue(u!=null);
		assertTrue(u.getId()==1);
		assertTrue(u.getType().equals("student"));
		assertTrue(u.getLogin().equals("ivanov_s"));
		assertTrue(u.getStudent()!=null);
	}
	
	public void testAddandDeleteStud() {
		User u = null;
		User udel=null;
		try {
			User user=new User();
			user.setId(new Long(1000));
			user.setLogin("login1000");
			user.setType("student");
			f.getUsersDAO().Add(user, "passssssssss");;
			try {
				u=f.getUsersDAO().getById(new Long(1000));
			} catch (Exception e) {e.printStackTrace();}	
				
			f.getUsersDAO().DeleteUser(user);
			
			try {
				udel=f.getUsersDAO().getById(new Long(1000));
			} catch (Exception e) {e.printStackTrace();}	
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		assertTrue(u!=null);
		assertTrue(udel==null);
	}
	
	public void testUpdateUserAndGetByLoginPass() {
		try {
			User user=f.getUsersDAO().getUserByLoginPass("ivanov_s", "qazxsw135");
						
			f.getUsersDAO().updateUserPassword(user, "fgfghj");
			User u2=null;
		try {
			u2=f.getUsersDAO().getUserByLoginPass("ivanov_s", "qazxsw135");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
			assertTrue(u2==null);
			
			f.getUsersDAO().updateUserPassword(user, "qazxsw135");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
				
	}
	
}
